package ua.edu.nuos.tees.jdmmon.gui.components;


import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;

/**
 * Logotype
 *
 * @author Olha Mudrievska
 *         19.05.13
 */
public class Logotype extends JPanel {

    private BufferedImage backgroundImage = null;

    public Logotype (URL imageUrl) {
        setImage(imageUrl);
    }

    /**
     * Set background image
     * @param imageUrl image URL address
     */
    public void setImage(URL imageUrl) {
        try {
            backgroundImage = ImageIO.read(imageUrl);
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }

    @Override
    public void paintComponent(Graphics g) {
        int xShift = (this.getSize().width - backgroundImage.getWidth()) / 2;
        int yShift = 5;
        super.paintComponent(g);
        g.drawImage(backgroundImage, xShift, yShift, null);
    }
}
